﻿#include "login_dialog.h"
#include "ui_logindialog.h"

#include <QMessageBox>
#include <QTextCodec>

LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent),
                                            ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
    setFixedSize(this->width(), this->height());
}

LoginDialog::~LoginDialog()
{
    delete ui;
}

void LoginDialog::on_loginButton_clicked()
{
    if (ui->usrLineEdit->text().trimmed() == tr("shusheng227") &&
        ui->pwdLineEdit->text() == tr("159357"))
    {
        accept();
    }
    else
    {
        QTextCodec *codec = QTextCodec::codecForName("GBK");
        QString msg = codec->toUnicode("用户名或密码错误");
        QMessageBox::warning(this, tr("Waring"), msg, QMessageBox::Ok);

        // 清空内容并定位光标
        ui->usrLineEdit->clear();
        ui->pwdLineEdit->clear();
        ui->usrLineEdit->setFocus();
    }
}
